package com.cqh.recruit.controller.student;



import com.cqh.recruit.pojo.dto.FeedbackDTO;
import com.cqh.recruit.pojo.entity.Feedback;
import com.cqh.recruit.result.Result;
import com.cqh.recruit.service.IFeedbackService;
import com.cqh.recruit.utils.StudentThreadLocal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 *
 *  前端控制器
 *
 *
 * @author dh
 * @since 2025-10-18
 * @version v1.0
 */
@RestController("studentFeedbackController")
@RequestMapping("/api/student/feedback")
@Tag(name = "学生反馈信息表接口")
public class FeedbackController {


    @Autowired
    private IFeedbackService feedbackService;


    /**
     * 提交活动反馈
     */
    @PostMapping("/submit")
    @Operation(summary = "提交活动反馈")
    public Result submitFeedback(@RequestBody FeedbackDTO feedbackDTO) {
        Long studentId = StudentThreadLocal.get().getId();

        return feedbackService.submitFeedback(studentId, feedbackDTO);
    }

    /**
     * 查询当前学生对某活动的反馈
     * 返回 null 表示未提交过反馈
     */
    @GetMapping("/findByActivity")
    @Operation(summary = "查询当前学生对某活动的反馈")
    public Result findFeedbackByActivity(@RequestParam Long activityId) {
        Long studentId = StudentThreadLocal.get().getId();
        Feedback feedback = feedbackService.findByStudentAndActivity(studentId, activityId);
        return Result.buildSuccess(feedback);
    }

}

